package com.thomas.sdk.manager;

import java.io.File;

import android.text.InputType;
import android.widget.EditText;
import android.widget.ImageView;

import com.thomas.sdk.R;

/**
 * 字符串操作工具类
 * 
 * @author thomas
 * 
 */
public class StringManager {

	public static void togglePwd(EditText pwdEt, ImageView lock) {
		if (pwdEt.getInputType() != InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
			lock.setImageResource(R.drawable.lock);
			pwdEt.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
		} else {
			lock.setImageResource(R.drawable.lock);
			pwdEt.setInputType(InputType.TYPE_CLASS_TEXT
					| InputType.TYPE_TEXT_VARIATION_PASSWORD);
		}
		pwdEt.setSelection(pwdEt.getText().toString().trim().length());
	}

	public static boolean isEmpty(String input) {
		return input == null || "".equals(input);
	}

	public static boolean isBadCellphone(String cellphone) {
		return cellphone.length() != 11;
	}

	public static boolean isBadPwd(String pwd) {
		return false;
	}

	public static boolean isBadVerificationCode(String code) {
		return code.length() != 6;
	}

	public static String getStringByET(EditText et) {
		return et.getText().toString().trim();
	}

	public static String getFileName(String filePath) {
		if (isEmpty(filePath))
			return "";
		return filePath.substring(filePath.lastIndexOf(File.separator) + 1);
	}

}
